package org.dromara.tearoom.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.tearoom.domain.vo.TerLockSerialnumVo;
import org.dromara.tearoom.domain.bo.TerLockSerialnumBo;
import org.dromara.tearoom.service.ITerLockSerialnumService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 门锁配置序号
 * 前端访问路由地址为:/tearoom/lockSerialnum
 *
 * @author xch
 * @date 2025-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lockSerialnum")
public class TerLockSerialnumController extends BaseController {

    private final ITerLockSerialnumService terLockSerialnumService;

    /**
     * 查询门锁配置序号列表
     */
    @SaCheckPermission("tearoom:lockSerialnum:list")
    @GetMapping("/list")
    public TableDataInfo<TerLockSerialnumVo> list(TerLockSerialnumBo bo, PageQuery pageQuery) {
        return terLockSerialnumService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出门锁配置序号列表
     */
    @SaCheckPermission("tearoom:lockSerialnum:export")
    @Log(title = "门锁配置序号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerLockSerialnumBo bo, HttpServletResponse response) {
        List<TerLockSerialnumVo> list = terLockSerialnumService.queryList(bo);
        ExcelUtil.exportExcel(list, "门锁配置序号", TerLockSerialnumVo.class, response);
    }

    /**
     * 获取门锁配置序号详细信息
     *
     * @param teroomId 主键
     */
    @SaCheckPermission("tearoom:lockSerialnum:query")
    @GetMapping("/{teroomId}")
    public R<TerLockSerialnumVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("teroomId") Long teroomId) {
        return R.ok(terLockSerialnumService.queryById(teroomId));
    }



    /**
     * 修改门锁配置序号
     */
    @SaCheckPermission("tearoom:lockSerialnum:edit")
    @Log(title = "门锁配置序号", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerLockSerialnumBo bo) {
        return toAjax(terLockSerialnumService.updateByBo(bo));
    }

    /**
     * 删除门锁配置序号
     *
     * @param teroomIds 主键串
     */
    @SaCheckPermission("tearoom:lockSerialnum:remove")
    @Log(title = "门锁配置序号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{teroomIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("teroomIds") Long[] teroomIds) {
        return toAjax(terLockSerialnumService.deleteWithValidByIds(List.of(teroomIds), true));
    }
}
